package com.mystore.framework.pojo;

import java.io.Serializable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Setter;
import lombok.Getter;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.util.StringUtils;

/**
 * 角色表(Role)实体类
 *
 * @author MyStore
 * @since 2023-06-28 14:04:58
 */

@Getter
@Setter
@Cacheable("role")
public class Role implements Serializable {
    private static final long serialVersionUID = -40227614669591359L;
    /**
     * 角色ID
     */
    @TableId(type = IdType.AUTO)
    private Integer roleId;
    /**
     * 角色名称
     */
    private String roleName;
    /**
     * 权限列表
     */
    private String rights;
    @TableField(exist = false)
    private TreeSet<String> uris;
    public TreeSet<String> getUris(){
        if(uris==null)
            if (StringUtils.hasText(rights))
                return new TreeSet<>(Arrays.asList(rights.split(",")));
            else
                return null;
        else
            return this.uris;
    }

}

